<template>
  <view style="background-color: #fff;">
    <view>
    	<uni-nav-bar shadow left-icon="left" dark title="供应商注册页面" @clickLeft="back" />
    </view>

  <view style="background-color: #fff;">
  	<uni-segmented-control :current="current" :values="items" styleType="button" activeColor="#ffaa00" @clickItem="onClickItem" style="background-color: #fff"  />
  </view>
  
  <view>

  	<view v-if="current === 0">
			<view>
			  <uni-card>
				  <uni-row style="margin-top: 10rpx;">
				  	<uni-col :span="7">
				  			<view style="line-height:70rpx;font-size:30rpx;">供应商编号:</view>
				  	</uni-col>
				  	<uni-col :span="16">
				  			<uni-easyinput type="text" v-model="SupplierForm.supplierCode" placeholder="供应商编号自动生成" disabled></uni-easyinput>
				  	</uni-col>
				  </uni-row>
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">供应商名称:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text" v-model="SupplierForm.supplierName" placeholder="请输入供应商名称"></uni-easyinput>
				</uni-col>
			</uni-row>
				<uni-row style="margin-top: 10rpx;">
					<uni-col :span="7">
							<view style="line-height:70rpx;font-size:30rpx;">简称:</view>
					</uni-col>
					<uni-col :span="16">
							<uni-easyinput type="text" v-model="SupplierForm.shortForm" placeholder="请输入简称"></uni-easyinput>
					</uni-col>
				</uni-row>
				
				<uni-row style="margin-top: 10rpx;">
					<uni-col :span="7">
							<view style="line-height:70rpx;font-size:30rpx;">英文名称:</view>
					</uni-col>
					<uni-col :span="16">
							<uni-easyinput type="text" v-model="SupplierForm.engName" placeholder="请输入英文名称"></uni-easyinput>
					</uni-col>
				</uni-row>
				
				<uni-row style="margin-top: 10rpx;">
					<uni-col :span="7">
							<view style="line-height:70rpx;font-size:30rpx;">地址:</view>
					</uni-col>
					<uni-col :span="16">
							<uni-easyinput type="text" v-model="SupplierForm.address" placeholder="请输入地址"></uni-easyinput>
					</uni-col>
				</uni-row>
								
				<uni-row style="margin-top: 10rpx;">
					<uni-col :span="7">
							<view style="line-height:70rpx;font-size:30rpx;">分组:</view>
					</uni-col>
					<uni-col :span="16">
						<uni-data-select
						      v-model="SupplierForm.groupCode"
						      :localdata="rangew"
						></uni-data-select>
							
					</uni-col>
				</uni-row>
				
				<uni-row style="margin-top: 10rpx;">
					<uni-col :span="7">
							<view style="line-height:70rpx;font-size:30rpx;">采购员:</view>
					</uni-col>
					<uni-col :span="16">
							 <uni-data-select
							      v-model="SupplierForm.slpCode"
							      :localdata="range"
							></uni-data-select>
					</uni-col>
				</uni-row>
				
				<uni-row style="margin-top: 10rpx;">
					<uni-col :span="7">
							<view style="line-height:70rpx;font-size:30rpx;">公司简介:</view>
					</uni-col>
					<uni-col :span="16">
							<uni-easyinput type="textarea" v-model="SupplierForm.companyProfile" placeholder="请输入公司简介"></uni-easyinput>
					</uni-col>
				</uni-row>  
			</uni-card>
			</view>
	</view>
  </view>
  
  	<view v-if="current === 1">
		<view>
			<uni-card>
		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="7">
					<view style="line-height:70rpx;font-size:30rpx;">统一码:</view>
			</uni-col>
			<uni-col :span="16">
					<uni-easyinput type="text" v-model="SupplierForm.unifiedSocialCreditCode" placeholder="请输入统一社会信用代码"></uni-easyinput>
			</uni-col>
		</uni-row>
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">组织代码:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text" v-model="SupplierForm.organizeCode" placeholder="请输入组织机构代码"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">企业类型:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text" v-model="SupplierForm.enterpType" placeholder="请输入企业类型"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">注册地:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text" v-model="SupplierForm.regCountryRegion" placeholder="请输入注册国家/地区"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">注册资本:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text"v-model="SupplierForm.registerCapital" placeholder="请输入注册资本(万)"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">建立日期:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-datetime-picker type="date" v-model="SupplierForm.creationDate" />

				</uni-col>
			</uni-row>
			
			<!-- <uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">主要身份:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text" v-model="SupplierForm.mainIdentity" placeholder="请输入主要身份"></uni-easyinput>
				</uni-col>
			</uni-row> -->
			

			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">主营品类:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text" v-model="SupplierForm.mainCategories" placeholder="请输入主营品类"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">认证地区:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text"v-model="SupplierForm.certificateRegion" placeholder="请输入认证地区"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">纳税人标识:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text"v-model="SupplierForm.taxpayerIdentify" placeholder="请输入纳税人标识"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">法定代表人:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text" v-model="SupplierForm.legalRepresent"placeholder="请输入法定代表人"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">注册币种:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text"v-model="SupplierForm.currency" placeholder="请输入注册资本币种"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			<!-- <uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">经营范围:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text"v-model="SupplierForm.businessScope" placeholder="请输入经营范围"></uni-easyinput>
				</uni-col>
			</uni-row> -->
			
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">经营性质:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text"v-model="SupplierForm.businessNature" placeholder="请输入经营性质"></uni-easyinput>
				</uni-col>
			</uni-row>
			
			
			<uni-row style="margin-top: 10rpx;">
				<uni-col :span="7">
						<view style="line-height:70rpx;font-size:30rpx;">公司官网:</view>
				</uni-col>
				<uni-col :span="16">
						<uni-easyinput type="text"v-model="SupplierForm.officialWebsite" placeholder="请输入公司官网"></uni-easyinput>
				</uni-col>
			</uni-row>
			</uni-card>
			
			
				
		
		</view>
		
	</view>
	
	<view v-if="current === 2">
		<view>
			<uni-card style="height: 300px;">
		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="7">
					<view style="line-height:70rpx;font-size:30rpx;">付款条件:</view>
			</uni-col>
			<uni-col :span="16">
					<uni-data-select
					      v-model="SupplierForm.pynmtGroup"
					      :localdata="ranges"
					></uni-data-select>
			</uni-col>
		</uni-row>
		
		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="7">
					<view style="line-height:70rpx;font-size:30rpx;">应付账款:</view>
			</uni-col>
			<uni-col :span="16">
					<uni-data-select
					      v-model="SupplierForm.acctCode"
					      :localdata="acctCode"
					></uni-data-select>
			</uni-col>
		</uni-row>
		</uni-card>
		</view>
	</view>
	
	<view v-if="current === 3">
		<view>
			<uni-card>		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="7">
					<view style="line-height:70rpx;font-size:30rpx;">联系人:</view>
			</uni-col>
			<uni-col :span="16">
					<uni-easyinput type="text"v-model="SupplierForm.contactPerson" placeholder="请输入联系人"></uni-easyinput>
			</uni-col>
		</uni-row>
		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="7">
					<view style="line-height:70rpx;font-size:30rpx;">职务:</view>
			</uni-col>
			<uni-col :span="16">
					<uni-easyinput type="text"v-model="SupplierForm.title" placeholder="请输入职务"></uni-easyinput>
			</uni-col>
		</uni-row>
		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="7">
					<view style="line-height:70rpx;font-size:30rpx;">电话:</view>
			</uni-col>
			<uni-col :span="16">
					<uni-easyinput type="text"v-model="SupplierForm.contactPhone" placeholder="请输入电话"></uni-easyinput>
			</uni-col>
		</uni-row>
		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="7">
					<view style="line-height:70rpx;font-size:30rpx;">传真:</view>
			</uni-col>
			<uni-col :span="16">
					<uni-easyinput type="text"v-model="SupplierForm.fax" placeholder="请输入传真"></uni-easyinput>
			</uni-col>
		</uni-row>
		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="7">
					<view style="line-height:70rpx;font-size:30rpx;">手机:</view>
			</uni-col>
			<uni-col :span="16">
					<uni-easyinput type="text"v-model="SupplierForm.cellPhone" placeholder="请输入手机"></uni-easyinput>
			</uni-col>
		</uni-row>
		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="7">
					<view style="line-height:70rpx;font-size:30rpx;">电子邮箱:</view>
			</uni-col>
			<uni-col :span="16">
					<uni-easyinput type="text"v-model="SupplierForm.email" placeholder="请输入电子邮箱地址"></uni-easyinput>
			</uni-col>
		</uni-row>
			
		<uni-row style="margin-top: 10rpx;">
			<uni-col :span="3">
					<view style="line-height:70rpx;font-size:30rpx;">备注:</view>
			</uni-col>
			<uni-col :span="20">
					<uni-easyinput type="textarea" v-model="SupplierForm.notes" placeholder="请输入内容"></uni-easyinput>
			</uni-col>
		</uni-row>
		</uni-card>

		
		
		
		</view>
	</view>
	
	<view v-if="current === 4">
		<view>
			<!-- <uni-table border stripe >
				<uni-tr style="white-space: nowrap;text-align: center;font-size: 12rpx;">
					<uni-th align="center">设备型号</uni-th>
					<uni-th align="center">设备名称</uni-th>
					<uni-th align="center">数量</uni-th>
					<uni-th align="center">备注</uni-th>
					<uni-th align="center"><button size="mini" @click="scriptAlias()">+</button></uni-th>
				</uni-tr>
				
				<uni-tr v-for="(item,index) in supplierDeviceFormList" :key="index" style="white-space: nowrap;text-align: center;font-size: 12rpx;">
					<uni-th align="center"><uni-easyinput v-model="item.deviceModel"></uni-easyinput></uni-th>
					<uni-th align="center"><uni-easyinput v-model="item.deviceName"></uni-easyinput></uni-th>
					<uni-th align="center"><uni-easyinput v-model="item.deviceAmount"></uni-easyinput></uni-th>
					<uni-th align="center"><uni-easyinput v-model="item.notes"></uni-easyinput></uni-th>
					<uni-th align="center">删除</uni-th>
				</uni-tr>
				</uni-table > -->
				
			<uni-table border stripe >	
			<uni-tr style="white-space: nowrap;text-align: center;font-size: 12rpx;">
				<uni-th align="center">设备型号</uni-th>
				<uni-th align="center">设备名称</uni-th>
				<uni-th align="center">数量</uni-th>
				<uni-th align="center">备注</uni-th>
				<uni-th align="center"><button size="mini" @click="addFormItem()">+</button></uni-th>
			</uni-tr>
			<uni-tr v-for="(item,index) in SupplierForm.supplierDeviceFormList" :key="index" style="white-space: nowrap;text-align: center;font-size: 12rpx;">
			<uni-td><uni-easyinput type="text" v-model="item.deviceModel" /></uni-td>
			<uni-td><uni-easyinput type="text" v-model="item.deviceName" /></uni-td>
			<uni-td><uni-easyinput type="text" v-model="item.deviceAmount" /></uni-td>
			<uni-td><uni-easyinput type="text" v-model="item.notes" /></uni-td>
			<uni-td><button size="mini" @click="removeFormItem(index)">删除</button></uni-td>
			</uni-tr>	
			</uni-table >	
		</view>
		
	</view>
  	<view v-if="current === 5">
		<view>
  		
	<!-- 上传照片 -->
	<uni-row style="margin-top: 10rpx;text-align: center;">
			<view :span="8" class="example-body" >
				<uni-file-picker limit="3" :value="fileLists" :image-styles="imageStyles" @select="select1" title="营业执照图"  />
			</view >
				
				<!-- file-mediatype="all" -->
	</uni-row>
	
	<uni-row style="margin-top: 10rpx;text-align: center;">
			<view :span="8" class="example-body" >
				<uni-file-picker limit="3" :value="fileLists" :image-styles="imageStyles" @select="select2" title="供应商资质图" />
			</view >
	</uni-row>
	
	<uni-row style="margin-top: 10rpx;text-align: center;">
			<view :span="8" class="example-body" >
				<uni-file-picker limit="3" :value="fileLists" :image-styles="imageStyles" @select="select3" title="供应商相册" />
			</view >
	</uni-row>
	
	
	
	<uni-row style="margin-top: 10rpx;text-align: center;">
			<uni-col :span="12"><button type="warn" size="mini" @click="clear()">取消</button></uni-col>
			<uni-col :span="12"><button type="primary" size="mini" @click="add()">提交</button></uni-col>
	</uni-row>
	</view>
  
	</view>

  </view>
 

  </view>
</template>

<script>
  import {fileUpload,uploadImgFile,addSave,SlierGroupFormDatatable,ProcurePersonFormDatatable} from '@/api/system/user'
       import { toast } from '@/utils/common'
import { jar } from 'request'
  export default {
    data() {
      return {
		// formItems: [],
        items: ['常规','合法信息', '付款条件','联系人','设备','附件'],
        current:0,
		fileLists:[],
		picList:[],
		rangew: [],
		range: [],
		ranges: [
			 { value: "", text: "-无-" },
			 { value: "款到发货", text: "款到发货"},
			 { value: "预付部分", text: "预付部分"},
			        ],
			acctCode: [
					        { value: "", text: "-无-" },
					        { value: "220201", text: "应付账款-国内"},
							{ value: "220202", text: "预收账款"},
					      ],
			vatStatus: [
			        { value: "", text: "-无-" },
			        { value: "应付", text: "应付"},
					{ value: "免税", text: "免税"},
			      ],
			eCVatGroup: [
			        { value: "", text: "-无-" },
			        { value: "J0", text: "进项税0%"},
					{ value: "J1", text: "进项税17%"},
					{ value: "J2", text: "进项税13%"},
					{ value: "J3", text: "进项税6%"},
					{ value: "J4", text: "进项税3%"},
					{ value: "J5", text: "进项税4%"},
					{ value: "J6", text: "进项税9%"},
					{ value: "J7", text: "进项税1%"},
					
			      ],					
		imageStyles:{
			width:100,
			height:100,
			border:{
			color:"#ffaaff",
			width:2,
			style:'dashed',
			radius:'2px'
						}
		},
		SupplierForm:{
			    openId:null,
				supplierCode:"",
				supplierDeviceFormList:[],
				docuIds:null,
				supplierName:null,//供应商名称
				shortForm:null,//简称
				engName:null,//英文名称
				address:null,//地址
				slpCode:null,//采购员
				slpName:null,
				groupCode:101,//分组编号	
				groupName:null,//分组名称
				status:"Y",
				companyProfile:null,
				//合法信息
				unifiedSocialCreditCode:null,//统一码
				organizeCode:null,//组织机构代码
				enterpType:null,//企业类型
				regCountryRegion:null,//注册地
				registerCapital:null,//注册资本
				creationDate:null,//建立日期
				mainIdentity:null,//主要身份
				industryType:null,//行业类型
				mainCategories:null,//主营品类
				certificateRegion:null,//认证地区
				taxpayerIdentify:null,//纳税人标识
				legalRepresent:null,//法定代表人
				currency:null,//注册资本币种
				businessScope:null,//经营范围
				businessNature:null,//经营性质
				officialWebsite:null,//公司官网
					
				//付款条件
				pynmtGroup:null,//付款条件
				listNum:null,//价格清单
				creditLine:null,//信用额度
				intrstRate:null,//欠款利息
				totalCount:null,//总计折扣
				debtLine:null,//承付款额度
				//合计
				account:null,//控制科目
				acctCode:null,//应付账款
				vatStatus:null,//纳税状态
				eCVatGroup:null,//税收组
				//备注
				notes:null,//备注
				contactPerson:null,
				title:null,
				contactPhone:null,
				fax:null,
				cellPhone:null,
				email:null,
				examineStatus:null,
				//附件
				businessLicense:null,//营业执照图
				// qualificationFile:null,//供应商资质
				// photoFile:null,//供应商相册
					}
		
		}
		       	
	  },
	   
	 onLoad() {
		 	const eventChannel = this.getOpenerEventChannel();
		 	eventChannel.on('acceptDataFromOpenerPage', (data) => {
		 	  this.SupplierForm.openId = data.data
			  alert( this.SupplierForm.openId)
		 	})
	 	 
		 //获取分组信息
	 	SlierGroupFormDatatable().then(res=>{
			this.table=res.rows
			
			let myrange = []
			this.table.forEach((val, index) => {
			myrange.push({
			value: val.groupCode,   // 选项id
			text:  val.groupName   // 选项名称
			        })
			 })
			 
			this.rangew = myrange
			
		})
		
		ProcurePersonFormDatatable().then(res=>{
			this.tables=res.rows
			let myranges = []
			this.tables.forEach((val, index) => {
			myranges.push({
			value: val.rowId,   // 选项id
			text:  val.personName   // 选项名称
			        })
			 })
			 
			this.range = myranges
			
		})
		
	
		
	 },
    methods: {
		
		
		  addFormItem() {
		    this.SupplierForm.supplierDeviceFormList.push({ deviceModel: null,deviceName: null,deviceAmount:null,notes: null });
					  
		  },
		  removeFormItem(index) {
		    this.SupplierForm.supplierDeviceFormList.splice(index, 1);
		  },
		
		
		add(){
			
		     var picIds = ""; 
			 for (let i = 0; i < this.picList.length; i++) {
			let pic = this.picList[i];
			 if(i==0){
			 picIds += pic;
			 continue;
			  }
			  picIds += ","+pic;
			 }
			this.SupplierForm.docuIds=picIds

	        this.rangew.forEach((item) => {
	          if (item.value ===this.SupplierForm.groupCode ) {
	            this.SupplierForm.groupName = item.text
	          }
	        })
			this.range.forEach((item) => {
			  if (item.value ===this.SupplierForm.slpCode ) {
			    this.SupplierForm.slpName = item.text
			  }
			})
		     
           // let SupplierForm=JSON.stringify(this.SupplierForm)
			addSave(this.SupplierForm).then(res=>{
			    this.$tab.redirectTo('/pages/login')
				alert("注册成功,等待审核")
			})
			// uni.showModal({
			// 	title: '提示',
			// 	content: '是否提交注册',
			// 	success: function (res) {
			// 		if (res.confirm) {
			// 			alert()
						
			// 		 }
			 
			// 	}
			// });
		},
		//上传图片
		select1(e){
		
			let file = e.tempFilePaths[0]
			let data = {
				filePath:file,
			}
			let data1 = {
				url: "supplier",
				code:"",
				docLabel: 'businessLicense',
			}
			uploadImgFile(data,data1).then(res=>{
				this.picList.push(res.data.fileId)
			})
			
			
		},
		select2(e){
		
			let file = e.tempFilePaths[0]
			let data = {
				filePath:file,
			}
			let data1 = {
				url: "supplier",
				code:"",
				docLabel: 'qualification',
			}
			uploadImgFile(data,data1).then(res=>{
				this.picList.push(res.data.fileId)
			})
			
			
		},
		select3(e){
		
			let file = e.tempFilePaths[0]
			let data = {
				filePath:file,
			}
			let data1 = {
				url: "supplier",
				code:"",
				docLabel: 'photo',
			}
			uploadImgFile(data,data1).then(res=>{
				this.picList.push(res.data.fileId)
			})
			
			
		},
		
		
		onClickItem(e) {
					if (this.current !== e.currentIndex) {
						this.current = e.currentIndex
					}
				},
		//返回登录页面
		back(){
			 this.$tab.redirectTo('/pages/login')
		},
		clear(){
			 this.$tab.redirectTo('/pages/login')
		},
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #fff;
  }
.example-body {
		padding: 10px;
		padding-top: 0;
	}

</style>
